angular.module('starter.controllers', [])

.controller('DashCtrl', function($scope) {})

.controller('ChatsCtrl', function($scope, museumFac, $stateParams, cfg) {
  // With the new view caching in Ionic, Controllers are only called
  // when they are recreated or on app start, instead of every page change.
  // To listen for when this page is active (for example, to refresh data),
  // listen for the $ionicView.enter event:
  //
  //$scope.$on('$ionicView.enter', function(e) {
  //});

  $scope.getTickes = function() {
    museumFac.ticket.tickets({
      exhibitionId:1
    },function(data){
      $scope.tickets = data.info;
    },function(data){
      alert(data.data.info);
    });
  };

  $scope.getOrders = function() {
    museumFac.order.ticketorders(function(data){
      $scope.orders = data.info;
    },function(data){
      alert(data.data.info);
    });
  };

  $scope.getExhibitions = function() {
    museumFac.info.exhibitions(function(data){
      $scope.exhibitions = data.info;
    },function(data){
      alert(data.data.info);
    });
  };

  $scope.gotoExhibition = function(exhibitionId){
    window.location.href = cfg.baseImgUrl + '/home/index/exhibition?exhibitionId=' + exhibitionId;
  }
  
})

.controller('ChatDetailCtrl', function($scope, museumFac, $stateParams, $http) {
  $scope.getTicket = function() {
    museumFac.ticket.ticket({
      ticketId:$stateParams.chatId
    },function(data){
      $scope.ticket = data.info;
    },function(data){
      alert(data.data.info);
    });
  };

  $scope.getRedeemCodes = function(ticketOrderId){
    museumFac.ticket.redeemcodes({
      ticketOrderId:ticketOrderId
    },function(data){
      $scope.codes = data.info;
    },function(data){
      alert(data.data.info);
    });
  }

  $scope.confirmOrder = function(){
    museumFac.ticket.confirmtorder({
      ticket_id:$stateParams.chatId,
      amount:$scope.ticket.amount
    },function(data){
      $scope.getRedeemCodes(data.info);
    },function(data){
      alert(data.data.info);
    });
  }

  $scope.allRedeemCode = function(){
    museumFac.ticket.allredeemcodes(function(data){
      $scope.codes = data.info;
    },function(data){
      alert(data.data.info);
    });
  }

  $scope.checkQr = function(code){
    code.qrimg = "http://pan.baidu.com/share/qrcode?w=150&h=150&url="+code.redeem_code;
  }
})

.controller('AccountCtrl', function($scope) {
  $scope.settings = {
    enableFriends: true
  };
});
